package com.zhny.aiot.bjxy.split.shape.plugin;

import com.zhny.aiot.bjxy.split.shape.plugin.model.SplitShapeStoreEntry;
import com.zhny.aiot.plugin.ICenterFacilities;
import com.zhny.aiot.plugin.IDeviceFactory;
import com.zhny.aiot.plugin.core.model.IRequestMessage;
import com.zhny.aiot.plugin.modbus.ModemEngine;
import com.zhny.aiot.plugin.modbus.device.ModemConfig;
import com.zhny.aiot.plugin.modbus.device.modbus.ModbusNumDevice;
import com.zhny.aiot.plugin.modbus.handler.model.ModemResponseMessage;
import com.zhny.aiot.plugin.model.DeviceEntity;
import com.zhny.aiot.plugin.model.TaskEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SplitShapeDevice extends ModbusNumDevice<SplitShapeStoreEntry> {
    private static final Logger logger = LoggerFactory.getLogger(SplitShapeDevice.class);
    public SplitShapeDevice(ModemEngine engine, IDeviceFactory<ModemConfig> factory, ICenterFacilities centerFacilities, DeviceEntity entity) {
        super(engine, factory, centerFacilities, entity);
    }

    @Override
    public SplitShapeStoreEntry decode(ModemResponseMessage modemResponseMessage) {
        SplitShapeStoreEntry entry = new SplitShapeStoreEntry();
        int temperature = modemResponseMessage.getData().readUnsignedShort();
        entry.setTemperature (temperature/10.0-50.0);
        return entry;
    }

    @Override
    public boolean checkError(ModemResponseMessage modemResponseMessage) {
        return modemResponseMessage.getData().readableBytes()== 2;
    }

    @Override
    protected IRequestMessage getCommand(TaskEntity taskEntity) {
        return getFactory().getRequestMessage(getConfig());
    }

    @Override
    protected void disposable() {

    }
}
